from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import base64
import json
import math
import time

key = b"5c5wRIVSYswSD7Sn"
iv = b"ssKqToSA9AzZXhNv"


def AES_Encrypt(word):
  aes = AES.new(key, AES.MODE_CBC, iv)
  padded_data = pad(word.encode(), AES.block_size)
  ciphertext = aes.encrypt(padded_data)
  return base64.b64encode(ciphertext).decode()

def AES_Decrypt(word):
    ciphertext = base64.b64decode(word)
    cipher = AES.new(key, AES.MODE_CBC, iv=iv)
    decrypted_data = unpad(cipher.decrypt(ciphertext), AES.block_size)
    return decrypted_data.decode('utf-8')


def get_data(time_id, x, y):
  data_list = {
    "app_id": "1000",
    "time_id": time_id,
    "x": x,
    "y": y,
    "y_data": [445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445,
               445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445,
               445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 444, 444, 444, 444, 444, 444, 444, 444,
               444, 444, 444, 444, 444, 444, 443, 442, 442, 442, 442, 442, 442, 442, 442, 442, 442, 442,
               442, 442, 442, 442, 441, 441, 441, 441, 441, 441, 441, 441, 441, 441, 441, 441, 441, 441,
               441, 441, 441, 441, 441, 441, 441, 441, 441, 441, 441, 441, 441, 441, 441, 441, 441, 441,
               441, 441, 441, 441, 441, 441, 441, 441, 441]
  }
  r_json = json.dumps(data_list)
  return AES_Encrypt(r_json)

def get_collect():
    r = {
        "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
        "ts": round(int(math.floor(time.time()))),
        "lang": "zh-CN",
        "sr": "1536x864",
        "sd": 24,
        "sw": 1536,
        "sh": 824,
        "cw": 459,
        "ch": 722,
        "bw": 442,
        "bh": 864,
        "ww": 459,
        "wh": 722,
        "dw": 459,
        "dh": 864
    }
    r_json = json.dumps(r)
    return AES_Encrypt(r_json)
# result=get_collect()
# print(result)